package file;

import java.io.File;
import java.io.FileFilter;

/**
 * Filter:过滤器
 * accept:接受
 * <p>
 * 获取一个项目中满足条件的所有子项
 * 满足
 */

public class LisefileDemo02 {
    public static void main(String[] args) {
        File dir = new File(".");
        if (dir.isDirectory()) {
            FileFilter filter = new FileFilter() {
                @Override
                public boolean accept(File file) {
                    String name = file.getName();
//                int index = name.indexOf("s");
//                return index >= 0;
                    return name.contains("s");
                }
            };
            File[] subs = dir.listFiles(filter);
            System.out.println(subs.length);
            for (int i = 0; i < subs.length; i++) {
                File sub = subs[i];
                System.out.println(sub);
            }
        }


    }
}
